package com.haohuo.config;

import com.haohuo.interceptor.RestTraceInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;

/**
 * RestTemplate配置
 *
 * @Author: pk.zhang
 * @Date: 2021/3/10 10:30
 */
@Configuration
public class RestTemplateConfig {

    @Autowired
    private RestTraceInterceptor restTraceInterceptor;

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        // 把自定义的RestTrackInterceptor添加到RestTemplate，这里可添加多个
        restTemplate.setInterceptors(Collections.singletonList(restTraceInterceptor));
        return restTemplate;
    }
}
